package net.starwifi.duobao.utils.times;

import java.beans.PropertyEditorSupport;

/**
 * Utils-DateAutoEditor.
 *
 * @author <a href="http://ruo.whosenet.com">ruo.whosenet.com</>
 * @version 1.0
 */
public class DateAutoEditor extends PropertyEditorSupport {

    public void setAsText(String text) throws IllegalArgumentException {
        if (!isBlank(text)) {
            text = text.trim();
            setValue(DateTool.autoParseDate(text));
        } else {
            setValue(null);
        }
    }

    private boolean isBlank(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if ((!Character.isWhitespace(str.charAt(i)))) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        DateAutoEditor dd = new DateAutoEditor();
        dd.setAsText("2012-08-25");
        System.out.println(dd.getValue());

        dd.setAsText("2012-08-25 21:23:12");
        System.out.println(dd.getValue());
    }
}